export const LOGIN_USER = "SFUSER";
export const LOGIN_TOKEN = "SFTOKEN";

// 保存登陆之后信息
export const saveLoginStorage = (userInfo) => {
  if (process.browser) {
    localStorage.setItem(LOGIN_USER, JSON.stringify(userInfo));
  }
  document.cookie = `${LOGIN_USER}=${JSON.stringify(userInfo)}; path=/`;
};

export const getLoginStorage = () => {
  // const userInfo = rocess.browser && localStorage.getItem(LOGIN_USER) ? JSON.parse(localStorage.getItem(LOGIN_USER)) : cookies(ctx)[LOGIN_USER];
  if (process.browser) {
    // 客户端
    const temp = localStorage.getItem(LOGIN_USER);
    return temp ? JSON.parse(temp) : {};
  }

};

export const saveToken = (token) => {
  localStorage.setItem(LOGIN_TOKEN, JSON.stringify(token));
  // document.cookie = `${LOGIN_TOKEN}=${token}; path=/`;
};

export const getToken = () => {
  if (process.browser) {
    // 客户端
    const temp = localStorage.getItem(LOGIN_TOKEN);
    return temp ? JSON.parse(temp) : "";
  }

};

export const clearLoginStorage = () => {
  localStorage.removeItem(LOGIN_USER);
  localStorage.removeItem(LOGIN_TOKEN);
};
